﻿namespace MicroBlog.Infrastructure
{
    /// <summary>
    /// 这些错误被返回给控制器，并且通常被用作最终用户的显示消息
    /// </summary>
    public static class ErrorDescriber
    {
        public static ContextError DefaultError()
        {
            return new ContextError
            {
                Code = nameof(DefaultError),
                Description = Resources.DefaultError
            };
        }
        public static ContextError DataNotFound()
        {
            return new ContextError
            {
                Code = nameof(DataNotFound),
                Description = "没有找到您要操作的数据"
            };
        }
        public static ContextError DuplicateUserName(string userName)
        {
            return new ContextError
            {
                Code = nameof(DuplicateUserName),
                Description = Resources.DuplicateUserName(userName)
            };
        }

        public static ContextError CredentialTypeNotFound(string credentialType)
        {
            return new ContextError
            {
                Code = nameof(CredentialTypeNotFound),
                Description = Resources.CredentialTypeNotFound(credentialType)
            };
        }

        public static ContextError CredentialNotFound(string credential)
        {
            return new ContextError
            {
                Code = nameof(CredentialNotFound),
                Description = Resources.CredentialNotFound(credential)
            };
        }

        public static ContextError UserAlreadyInRole(string role, string user)
        {
            return new ContextError
            {
                Code = nameof(UserAlreadyInRole),
                Description = Resources.UserAlreadyInRole(role, user)
            };
        }
        public static ContextError UserNotInRole(string role, string user)
        {
            return new ContextError
            {
                Code = nameof(UserNotInRole),
                Description = Resources.UserNotInRole(user, role)
            };
        }

        public static ContextError PasswordMismatch()
        {
            return new ContextError
            {
                Code = nameof(PasswordMismatch),
                Description = Resources.PasswordMismatch
            };
        }
        public static ContextError LoginFailed()
        {
            return new ContextError
            {
                Code = nameof(LoginFailed),
                Description = Resources.LoginFailed
            };
        }
        public static ContextError InvalidUserName(string userName)
        {
            return new ContextError
            {
                Code = nameof(InvalidUserName),
                Description = Resources.InvalidUserName(userName)
            };
        }
        public static ContextError RoleNotFound(string roleCode)
        {
            return new ContextError
            {
                Code = nameof(RoleNotFound),
                Description = Resources.RoleNotFound(roleCode)
            };
        }
        public static ContextError UserNotFound()
        {
            return new ContextError
            {
                Code = nameof(UserNotFound),
                Description = Resources.UserNotFound
            };
        }
        public static ContextError OperateFailed(string message)
        {
            return new ContextError
            {
                Code = nameof(OperateFailed),
                Description = Resources.OperateFailed(message)
            };
        }
    }
}
